package test.luin.pers.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

public class MainActivity extends Activity implements View.OnClickListener {

    private Button loginButton;
    private EditText number;
    private EditText password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

        //加载保存成功的用户信息
//        Map<String,String> userInfo = SaveFile.GetUserInfor(this);
        Map<String, String> userInfo = SaveFileQQ.getUserInfor(this);
        if (userInfo != null) {
            number.setText(userInfo.get("username"));
            password.setText(userInfo.get("password"));
        }

    }

   public   void send(View view) {
        Intent intent = new Intent();
        intent.setAction("cn.edu.jzsz.Help");
        sendBroadcast(intent);
    }

    void init() {
        number = (EditText) findViewById(R.id.et_number);
        password = (EditText) findViewById(R.id.et_password);
        loginButton = (Button) findViewById(R.id.btn_login);
        loginButton.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        String txt_number = number.getText().toString();
        String txt_password = password.getText().toString();
        if (TextUtils.isEmpty(txt_number)) {
            Toast.makeText(this, "请输入QQ号码", Toast.LENGTH_LONG).show();
            return;
        }
        if (TextUtils.isEmpty(txt_password)) {
            Toast.makeText(this, "请输入QQ密码", Toast.LENGTH_LONG).show();
            return;
        }
//        boolean isSuccess = SaveFile.SaveFileInfor(this, txt_number, txt_password);
        boolean isSuccess = SaveFileQQ.saveUserInfor(this, txt_number, txt_password);
        if (isSuccess) {
            Toast.makeText(this, "保存成功", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "保存失败", Toast.LENGTH_LONG).show();
        }
    }

}
